package org.dawnframework.context.annotation;

import org.dawnframework.beans.factory.config.BeanDefinition;
import org.dawnframework.beans.factory.config.ContextScope;
import org.dawnframework.core.type.Lazy;
import org.dawnframework.core.type.Scope;

public abstract class AbstractBeanDeinition implements BeanDefinition {


    private boolean islazy = false;



    private String scopeName = ContextScope.singleton.name();
    /**
     * 默认单例
     **/
    private boolean isSingleton = true;

    private String beanClassName;


    /**
     * 获取子类的beanClass
     *
     * @return
     */
    public abstract Class<?> getBeanClass();


    @Override
    public boolean isLazy() {
        islazy  = getBeanClass().isAnnotationPresent(Lazy.class);
        return islazy;
    }



    @Override
    public String getScopeName() {
        return scopeName;
    }

    @Override
    public boolean isSingleton() {
        Class<?> beanClzz = getBeanClass();
        if (beanClzz.isAnnotationPresent(Scope.class)) {
            scopeName = beanClzz.getAnnotation(Scope.class).value();
            if (scopeName.equals(ContextScope.singleton)) {
                isSingleton = true;
            }
        }
        return isSingleton;
    }

    @Override
    public boolean isPrototype() {
        return scopeName.equals(ContextScope.prototype);
    }

    @Override
    public boolean isAbstract() {
        return getBeanClass().isInterface();
    }
    @Override
    public void setBeanClassName(String beanClassName) {
      this.beanClassName = beanClassName == null ? getBeanClass().getName():beanClassName;
    }

    @Override
    public String geBeanClassName() {
        return beanClassName;
    }
    @Override
    public void setScopeName(String scopeName) {
     this.scopeName = scopeName;
    }
}
